package Servlets;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import QueryExcecution.EnterSchemeDetails;
import beanUtils.BeanUtility;
import beans.FundSchemeBean;


public class AddFundSchemeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    FundSchemeBean fsb;
    EnterSchemeDetails esd;
    
    public AddFundSchemeServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		esd = new EnterSchemeDetails();
		fsb = new FundSchemeBean();
		BeanUtility.populateBean(fsb, request);
		
		String FHCode=null;
		String fundHouseCode = esd.getfundHouseCode(request.getParameter("fund_house_name"));
	/*	try {
			if(fundHouseCode.next()){
				//fsb.setFund_house_Id(fundHouseCode.getString("AMC_ID"));
				FHCode = fundHouseCode.getString("AMC_ID");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} */
		
		fsb.setFund_house_Id(fundHouseCode);
		
		if(request.getParameter("Redeem")==null){
			fsb.setRedeem("false");
		}else{
			fsb.setRedeem("true");
		}
		
		if(request.getParameter("Purchase")==null){
			fsb.setPurchase("false");
		}else{
			fsb.setPurchase("true");
		}
		
		if(request.getParameter("SIP")==null){
			fsb.setSIP("false");
		}else{
			fsb.setSIP("true");
		}
		
		if(request.getParameter("sip_frequency")==null){
			fsb.setSip_frequency("false");
		}else{
			fsb.setSip_frequency("true");
		}
		
		if(request.getParameter("switch_available")==null){
			fsb.setSwitch_available("-");
		}else{
			fsb.setSwitch_available("M");
		}
		
		//fsb.setMin_purchase();
		
		esd.addScheme(fsb);
	}
}
